using System;
using SMS.Entities.BaseClasses;

namespace SMS.Entities
{
    public class SaleDetail : BaseEntity
    {

        private int _SaleDetail_ID;

        public int SaleDetail_ID
        {
            get { return _SaleDetail_ID; }
            set { _SaleDetail_ID = value; OnPropertyChanged("SaleDetail_ID"); }
        }


        private SaleHistory _SalesHistory;
        public SaleHistory SalesHistory
        {
            get { return _SalesHistory; }
            set
            {
                _SalesHistory = value;
                OnPropertyChanged("SalesHistory");
            }
        }

        private ProductStockWise _ProductStockWise;
        public ProductStockWise ProductStockWise
        {
            get { return _ProductStockWise; }
            set
            {
                _ProductStockWise = value;
                OnPropertyChanged("ProductStockWise");
            }
        }

        private int _Product_Stock_ID;
        public int Product_Stock_ID
        {
            get { return _Product_Stock_ID; }
            set
            {
                _Product_Stock_ID = value;
                OnPropertyChanged("Product_Stock_ID");
            }
        }

        private int _Quantity;

        public int Quantity
        {
            get { return _Quantity; }
            set { _Quantity = value; ProcessBill(); OnPropertyChanged("Quantity"); }
        }


        private Decimal _SellingUnitPrice;
        public Decimal SellingUnitPrice
        {
            get { return _SellingUnitPrice; }
            set
            {
                _SellingUnitPrice = value;
                ProcessBill();
                OnPropertyChanged("SellingUnitPrice");
            }
        }
        private Decimal _BilledAmount;

        public Decimal BilledAmount
        {
            get { return _BilledAmount; }
            set { _BilledAmount = value; OnPropertyChanged("BilledAmount"); }
        }

        private Decimal _TotalAmount;
        public Decimal TotalAmount
        {
            get { return _TotalAmount; }
            set
            {
                _TotalAmount = value;
                OnPropertyChanged("TotalAmount");
            }
        }

        private Decimal _Discount;
        public Decimal Discount
        {
            get { return _Discount; }
            set
            {
                _Discount = value;
                ProcessBill();
                OnPropertyChanged("Discount");
            }
        }

        private Decimal _DiscountValue;
        public Decimal DiscountValue
        {
            get { return _DiscountValue; }
            set
            {
                _DiscountValue = value;
                OnPropertyChanged("DiscountValue");
            }
        }

        private Decimal _TotalCost;

        public Decimal TotalCost
        {
            get { return _TotalCost; }
            set { _TotalCost = value; OnPropertyChanged("TotalCost"); }
        }


        public override string ToObjectString()
        {
            return string.Format("Sale_ID={0}, ProductStockWiseID={1}, CurrentTime={2}", this.SalesHistory == null ? string.Empty : this.SalesHistory.Sale_ID.ToString(),
                this.ProductStockWise == null ? string.Empty : this.ProductStockWise.Product_Stock_ID.ToString(), DateTime.Now);

        }

        public void ProcessBill()
        {
            TotalAmount = SellingUnitPrice * Quantity;
            DiscountValue = TotalAmount * (Discount * Convert.ToDecimal(.01));
            BilledAmount = TotalAmount - DiscountValue;
        }
    }
}